package com.mystudy.leetcode.problem.hash.p_349;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 周志龙
 * @Email 15216876513@163.com
 * @Date on 2019/7/29 21:48
 * @Description 两个数组的交集
 */
public class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> result = new HashSet<>();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            set.add(nums1[i]);
        }
        for (int i = 0; i < nums2.length; i++) {
            if (set.contains(nums2[i])) {
                result.add(nums2[i]);
            }
        }
        int[] r = new int[result.size()];
        int i = 0;
        for (Integer integer : result) {
            r[i] = integer;
            i++;
        }
        return r;
    }
}
